/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 *
 */


import { expect, test } from '@jest/globals';

import { OptCompressionBuilder } from '../../../src/builder/opt-compression-builder.js';

test('test processSize', () => {
  const optCompressionBuilder = new OptCompressionBuilder();
  optCompressionBuilder.setCompressionConfig({
    filters: [
      {
        method:{
          type: 'sut',
          blocks: '4x4'
        },
        files: {
          size: [
            [0, '1k'],
            [1024, '2048'],
            [100, 0]
          ]
        },
        exclude: {
          size: [
            [0, 100],
            [101]
          ]
        }
      }
    ]
  });
  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].rules_origin?.size)
    .toStrictEqual([[0, 2048]]);
  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].rules_exclude?.size)
    .toStrictEqual([[0]]);
});

test('test default filter', () => {
  const optCompressionBuilder = new OptCompressionBuilder();
  optCompressionBuilder.setCompressionConfig({
    media: {
      enable: true
    }
  });
  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].method).toStrictEqual({
    type: 'sut',
    blocks: '4x4'
  });

  optCompressionBuilder.setCompressionConfig({
    media: {
      enable: true
    },
    filters: []
  });
  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].method).toStrictEqual({
    type: 'sut',
    blocks: '4x4'
  });
});

test('test empty exclude', () => {
  const optCompressionBuilder = new OptCompressionBuilder();
  optCompressionBuilder.setCompressionConfig({
    filters: [
      {
        method:{
          type: 'sut',
          blocks: '4x4'
        },
        files: {
          path: ['./**/*.png']
        },
        exclude: { }
      }
    ]
  });
  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].exclude_path).toStrictEqual([]);

  optCompressionBuilder.setCompressionConfig({
    filters: [
      {
        method:{
          type: 'sut',
          blocks: '4x4'
        },
        files: {
          path: ['./**/*.png']
        }
      }
    ]
  });
  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].exclude_path).toStrictEqual([]);
});

test('test processResolution', () => {
  const optCompressionBuilder = new OptCompressionBuilder();
  optCompressionBuilder.setCompressionConfig({
    filters:[
      {
        method:{
          type: 'sut',
          blocks: '4x4'
        },
        files: {
          resolution: [
            [
              { width: 0, height: 0 },
              { width: 100, height: 100 },
            ],
            [
              { width: 100, height: 100 },
              { width: 0, height: 0 },
            ],
            [
              { width: 100, height: 100 },
            ],
          ]
        }
      }
    ]
  });

  expect(optCompressionBuilder.getOptCompressionObj().compression.filters[0].rules_origin?.resolution?.length).toBe(2);
});


